<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <!--    <div class="table-page-search-wrapper">-->
    <!--      <a-form layout="inline" @keyup.enter.native="searchQuery">-->
    <!--        <a-row :gutter="24">-->

    <!--          <a-col :md="12" :sm="12">-->

    <!--            <a-col :md="6" :sm="6">-->
    <!--              <a-form-item label="物料名称">-->
    <!--                <a-input placeholder="请输入物料名称" v-model="queryParam.productName"></a-input>-->
    <!--              </a-form-item>-->
    <!--            </a-col>-->
    <!--            <a-col :md="6" :sm="6">-->
    <!--              <a-form-item label="物料代码">-->
    <!--                <a-input placeholder="请输入物料代码" v-model="queryParam.productCode"></a-input>-->
    <!--              </a-form-item>-->
    <!--            </a-col>-->
    <!--          </a-col>-->

    <!--          <a-col :md="12" :sm="12">-->
    <!--            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">-->
    <!--              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>-->
    <!--              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>-->

    <!--            </span>-->
    <!--          </a-col>-->
    <!--        </a-row>-->
    <!--      </a-form>-->
    <!--    </div>-->
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-button type="primary" @click="createPurchaseOrder" icon="add" style="margin-bottom:20px">生成采购单</a-button>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
      </a-table>
    </div>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { queryhistorylist } from '@/api/api'
import { getAction } from '@api/manage'
export default {
  name: 'HfPurchaseSuggest',
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      description: '采购建议单',
      saleorderid: '',

      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '物料代码',
          align: 'center',
          dataIndex: 'productCode'
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'productName'
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'sap'
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit'
        },
        {
          title: '需要采购数量',
          align: 'center',
          dataIndex: 'number'
        },
        {
          title: '库存',
          align: 'center',
          dataIndex: 'totoaPrice'
        },
        {
          title: '订单数量',
          align: 'center',
          dataIndex: 'price'
        }
      ],
      url: {
        list: '/sale/hfSaleOrder/purchasesuggest',
        createpurchaseorder: '/sale/hfSaleOrder/createPurchaseOrder'
      },

      dictOptions: {}
    }
  },
  created() {},
  computed: {},
  methods: {
    openlist(id) {
      this.queryParam.id = id
      this.saleorderid = id
      this.loadData(1)
    },
    createPurchaseOrder() {
      getAction(this.url.createpurchaseorder, { id: this.saleorderid }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    loadSuggestData(arg) {
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      this.loading = true
      let that = this
      getAction(that.url.list, params)
        .then(res => {
          if (res.success) {
            that.dataSource = res.result.records
            if (res.result.total) {
              that.ipagination.total = res.result.total
            } else {
              that.ipagination.total = 0
            }
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.loading = false
        })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
